
mergeInto(LibraryManager.library, {
  BinFileDownloader: function(str, fn, type) {
     var msg = UTF8ToString(str);  // 替换关键函数
     var fname = UTF8ToString(fn);
     var contentType = UTF8ToString(type);
    
    function fixBinary(bin) {
      var buf = new ArrayBuffer(bin.length);
      var arr = new Uint8Array(buf);
      for(var i=0; i<bin.length; i++) {
        arr[i] = bin.charCodeAt(i);
      }
      return buf;
    }

    var binary = fixBinary(atob(msg));
    var data = new Blob([binary], {type: contentType});
    var link = document.createElement('a');
    link.download = fname;
    link.href = window.URL.createObjectURL(data);
    document.body.appendChild(link);
    link.click();
    setTimeout(() => {
      document.body.removeChild(link);
      window.URL.revokeObjectURL(link.href);
    }, 100);
  }
});
